package top.wangjiu.java.jvm.constantinfo.refrence;

import top.wangjiu.java.jvm.constantinfo.ConstantPoolInfo;
import top.wangjiu.java.jvm.constantinfo.SymbolicReferenceConstantPoolInfo;

/**
 * @ClassName MethodrefInfo
 * @Description TODO
 * @Author wangjiu
 * @Date 2022/1/14 11:56 上午
 */
public class InterfaceMethodrefCPInfo extends SymbolicReferenceConstantPoolInfo {

    public final static short TAG = 11;
    public final static short INFO_LENGTH = 4;
    private final short index;
    private final short classIndex;

    private final short nameAndTypeIndex;

    public InterfaceMethodrefCPInfo(byte[] bytes, short index){
        this.index = index;
        classIndex = (short)(bytes[0] << 8 | bytes[1]);
        nameAndTypeIndex = (short)(bytes[2] << 8 | bytes[3]);
    }

    @Override
    public short tag() {
        return TAG;
    }

    @Override
    public short index() {
        return index;
    }

    @Override
    public short infoLength() {
        return INFO_LENGTH;
    }

    @Override
    public String toFullString(ConstantPoolInfo[] poolInfos) {
        return "#"+index +" = InterfaceMethodref" + "\t\t#"+classIndex +".#"+ nameAndTypeIndex+ "\t\t// "+poolInfos[classIndex].toString(poolInfos) + "."+poolInfos[nameAndTypeIndex].toString(poolInfos);
    }

    @Override
    public String toString(ConstantPoolInfo[] poolInfos) {
        return poolInfos[classIndex].toString(poolInfos) + "."+poolInfos[nameAndTypeIndex].toString(poolInfos);
    }
}
